package com.finger.wx.assistant.util.xml;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UiXml {

	/** resource_id **/
	private String id;
	/**
	 * 文本内容
	 */
	private String text;

	/**
	 * 组件属性
	 */
	private String nclass;

	/**
	 * 组件所在区域
	 */
	private String bounds;

	/**
	 * 组件的中心坐标x
	 */
	private int x;

	/**
	 * 组件的中心坐标y
	 */
	private int y;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getNclass() {
		return nclass;
	}

	public void setNclass(String nclass) {
		this.nclass = nclass;
	}

	public String getBounds() {
		return bounds;
	}

	public void setBounds(String bounds) {
		this.bounds = bounds;
	}

	public int getX() {
		int x = 0;
		if (bounds != null && !bounds.equals("")) {
			Pattern p1 = Pattern.compile("\\[(\\d+),(\\d+)\\]");
			Matcher m1 = p1.matcher(bounds);
			while (m1.find()) {
				x += Integer.parseInt(m1.group(1));
			}
		}
		return x / 2;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		int y = 0;
		if (bounds != null && !bounds.equals("")) {
			Pattern p1 = Pattern.compile("\\[(\\d+),(\\d+)\\]");
			Matcher m1 = p1.matcher(bounds);
			while (m1.find()) {
				y += Integer.parseInt(m1.group(2));
			}
		}
		return y / 2;
	}

	public void setY(int y) {
		this.y = y;
	}
}
